package cn.youqu.happy.module.youqu.convert.userActivity;

import cn.hutool.core.collection.CollUtil;
import cn.youqu.happy.framework.common.pojo.PageResult;
import cn.youqu.happy.module.youqu.controller.admin.userActivity.vo.*;
import cn.youqu.happy.module.youqu.controller.app.userActivity.vo.AppUserActivityCreateReqVO;
import cn.youqu.happy.module.youqu.controller.app.userActivity.vo.AppUserActivityPageReqVO;
import cn.youqu.happy.module.youqu.controller.app.userActivity.vo.AppUserActivityRespVO;
import cn.youqu.happy.module.youqu.controller.app.userActivity.vo.AppUserActivityUpdateReqVO;
import cn.youqu.happy.module.youqu.dal.dataobject.userActivity.UserActivityDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户发起活动 Convert
 *
 * @author 王其岩 20112001045
 */
@Mapper(componentModel = "spring")
public interface UserActivityConvert {

    UserActivityConvert INSTANCE = Mappers.getMapper(UserActivityConvert.class);

    @Mappings({
            @Mapping(target = "img", source = "imgList"),
    })
    UserActivityDO convert(UserActivityCreateReqVO bean);

    @Mappings({
            @Mapping(target = "img", source = "imgList"),
    })
    UserActivityDO convert(UserActivityUpdateReqVO bean);

    @Mappings({
            @Mapping(target = "imgList", source = "img"),
            @Mapping(target = "partnerList", source = "partners")
    })
    UserActivityRespVO convert(UserActivityDO bean);


    List<UserActivityRespVO> convertList(List<UserActivityDO> list);


    PageResult<UserActivityRespVO> convertPage(PageResult<UserActivityDO> page);


    List<UserActivityExcelVO> convertList02(List<UserActivityDO> list);

    @Mappings({
            @Mapping(target = "imgList", source = "img"),
            @Mapping(target = "partnerList", source = "partners")
    })
    AppUserActivityRespVO convert0(UserActivityDO userActivity);


    List<AppUserActivityRespVO> convertList0(List<UserActivityDO> list);


    PageResult<AppUserActivityRespVO> convertPage0(PageResult<UserActivityDO> pageResult);

    @Mappings({
            @Mapping(target = "img", source = "createReqVO.imgList"),
    })
    UserActivityDO convert(AppUserActivityCreateReqVO createReqVO, Long uid);

    @Mappings({
            @Mapping(target = "img", source = "createReqVO.imgList"),
            @Mapping(target = "partners", source = "createReqVO.partnerList")
    })
    UserActivityDO convert(AppUserActivityUpdateReqVO createReqVO, Long uid);


    UserActivityPageReqVO convert(AppUserActivityPageReqVO pageVO);

    default List<String> str2List(String str) {
        if (str == null || str.isEmpty()) return new ArrayList<>();
        String[] split = str.split(",");
        return Arrays.asList(split);
    }

    default String list2str(List<String> src) {
        if (CollUtil.isEmpty(src)) {
            return null;
        }
        return String.join(",", src);
    }

    default List<Long> str2List2(String src) {
        if (src == null || src.isEmpty()) return new ArrayList<Long>();
        String[] split = src.split(",");
        return Arrays.stream(split).map(item -> Long.valueOf(item)).collect(Collectors.toList());
    }

    default String list2Str2(List<Long> src) {
        if (CollUtil.isEmpty(src)) {
            return null;
        }
        List<String> collect = src.stream().map(item -> String.valueOf(item)).collect(Collectors.toList());
        return String.join(",", collect);
    }

}
